package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author: hea7en
 * @Date: 2024/5/21 11:23 AM
 * @Description: 购物车Mapper
 */
@Mapper
public interface ShoppingCartMapper {

    /**
     * 查询购物车商品列表
     * @param cart
     * @return
     */
    List<ShoppingCart> getCartList(ShoppingCart cart);

    /**
     * 更新购物车商品
     * @param shoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 添加购物车商品
     * @param cart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void add(ShoppingCart cart);

    /**
     * 根据用户id查询购物车
     * @param currentId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{currentId}")
    List<ShoppingCart> getListByUserId(Long currentId);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    /**
     * 删除购物车商品
     * @param cart
     */
    void delete(ShoppingCart cart);
}
